Proper Tail Recursion and Space Eeciency

نویسنده

  • William D Clinger
چکیده

The IEEE/ANSI standard for Scheme requires implementations to be properly tail recursive. This ensures that portable code can rely upon the space eeciency of continuation-passing style and other idioms. On its face, proper tail recursion concerns the eeciency of procedure calls that occur within a tail context. When examined closely, proper tail recur-sion also depends upon the fact that garbage collection can be asymptotically more space-eecient than Algol-like stack allocation. Proper tail recursion is not the same as ad hoc tail call optimization in stack-based languages. Proper tail recursion often precludes stack allocation of variables, but yields a well-deened asymptotic space complexity that can be relied upon by portable programs. This paper ooers a formal and implementation-independent deenition of proper tail recursion for Scheme. It also shows how an entire family of reference implementations can be used to characterize related safe-for-space properties, and proves the asymptotic inequalities that hold between them. 1 Introduction Tail recursion is a phrase that has been used to refer to various syntactic notions, to particular techniques for implementing syntactic tail recursion, and to the space eeciency of those techniques. Syntactically, a call is a tail call if it appears within a function body that can reduce to the call; this is formalized in Section 2. Since the complete call graph is seldom available, a tail call is often said to be tail recur-sive regardless of whether it occurs within a cycle in the call graph. Scheme, Standard ML, and several other mostly-functional languages rely heavily on the eeciency of tail recursion. Common idioms, notably continuation-passing style (CPS), would quickly run out of stack space if tail calls were to consume space. To ensure that portable code can rely upon these idioms, the IEEE standard for Scheme IEE91] says Implementations of Scheme are required to be properly tail-recursive Ste78]. This allows the

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Space-Efficient Latent Contracts

Standard higher-order contract monitoring breaks tail recursion and leads to space leaks that can change a program’s asymptotic complexity; space-efficiency restores tail recursion and bounds the amount of space used by contracts. Space-efficient contract monitoring for contracts enforcing simple type disciplines (a/k/a gradual typing) is well studied. Prior work establishes a space-efficient s...

متن کامل

SLDMagic | An Improved Magic Set Technique

We present a rewriting method for Datalog-programs which simulates SLD-resolution more closely than the ordinary \magic set" method does. This is especially advantageous in the case of tail-recursive programs, but already in non-recursive programs we can often save a number of joins. In contrast to the method of Ross 7], we do not only solve the problem of tail-recursion, but try to simulate SL...

متن کامل

CSci 450: Org. of Programming Languages Evaluation and Efficiency

3 Evaluation and Efficiency 2 3.1 Chapter Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 2 3.2 Evaluation of Functional Programs . . . . . . . . . . . . . . . . . 2 3.2.1 Referential transparency . . . . . . . . . . . . . . . . . . . 3 3.2.2 Substitution model . . . . . . . . . . . . . . . . . . . . . . 3 3.2.3 Time and space complexity . . . . . . . . . . . . . . . . . 7 3.2.4 ...

متن کامل

Time-Dependent Real-Space Renormalization Group Method

In this paper, using the tight-binding model, we extend the real-space renormalization group method to time-dependent Hamiltonians. We drive the time-dependent recursion relations for the renormalized tight-binding Hamiltonian by decimating selective sites of lattice iteratively. The formalism is then used for the calculation of the local density of electronic states for a one dimensional quant...

متن کامل

Tail Recursion without Space Leaks

The G-machine (Johnsson, 1987; Peyton Jones, 1987) is a compiled graph reduction machine for lazy functional languages. The G-machine compiler contains many optimisations to improve performance. One set of such optimisations is designed to improve the performance of tail recursive functions. Unfortunately the abstract machine is subject to a space leak—objects are unnecessarily preserved by the...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1998